require 'mxcslider'

class Equalizer < Qt::Widget
	slots	'toggleEqualizer()'

	signals 'toggleEq(bool)'

	def initialize(parent = nil, name = nil)
		super

		@client = MXmms2Client.instance

		setFocusPolicy(TabFocus)
		initSliders
		connectEq
		setMinimumHeight(160)

	end

	def initSliders
		@vlay1 = Qt::VBoxLayout.new(self, 5, 5)

		@gbox = Qt::GroupBox.new('Equalizer', self) {
			setColumnLayout(0, Horizontal)
			layout.setSpacing(5)
			layout.setMargin(5)
			layout.setAlignment(AlignTop)
		}

		@on = Qt::CheckBox.new('On', @gbox)

		@gbox.layout.addWidget(@on)

		@grid3 = Qt::GridLayout.new(nil, 2, 10, 0, 6) {
			setSpacing(5)
			setMargin(5)
		}

		10.times { |x|
			instance_variable_set :"@lab#{x}", Qt::Label.new(x.to_s, @gbox)
			tmp =  MxcSlider.new(Vertical,@gbox) {
				setRange(-100, 1)
				setSteps(1, 1)
				setTickInterval(50)
				setTickmarks(MxcSlider::Right)
			}
			instance_variable_set :"@band#{x}", tmp
			@grid3.addWidget(instance_variable_get(:"@lab#{x}"), 0, x*2)
			@grid3.addWidget(instance_variable_get(:"@band#{x}"), 1, x*2)
		}
	
		1.step(18,2) {|x|
			spacer = Qt::SpacerItem.new(0, 0, Qt::SizePolicy::Minimum, Qt::SizePolicy::Minimum)
			@grid3.addItem(spacer, 0, x)
		}

		@gbox.layout.addLayout(@grid3)
		@vlay1.addWidget(@gbox)
	end

	def connectEq
		10.times { |x|
			connect(@client, SIGNAL("setBand#{x}Value(int)"), instance_variable_get(:"@band#{x}"), SLOT('setValue(int)'))
			connect(instance_variable_get(:"@band#{x}"), SIGNAL('sliderMoved(int)'), @client, SLOT("setBand#{x}Val(int)"))
		}

		connect(@client, SIGNAL('toggleEqualizer(bool)'), @on, SLOT('setChecked(bool)'))
		connect(@on, SIGNAL('clicked()'), SLOT('toggleEqualizer()'))
		connect(self, SIGNAL('toggleEq(bool)'), @client, SLOT('toggleEq(bool)'))
	end

	def toggleEqualizer
		emit toggleEq(@on.isChecked)
	end

end


